﻿using System;
using CoreTypes;
using System.Custom.Window;
using System.Globalization;
using System.Windows.Forms;
using System.ComponentModel;

namespace MainModule
{
   public partial class RemoveContactWindow : Window
   {
      Contact FContact;
      InternetCommunicator FCommunicator = InternetCommunicator.Self;

      public RemoveContactWindow()
      {
         InitializeComponent();

         FCommunicator.PropertyChanged += communicator_PropertyChanged;
      }
      protected override void Dispose(bool disposing)
      {
         FCommunicator.PropertyChanged -= communicator_PropertyChanged;

         if (disposing && (components != null))
         {
            components.Dispose();
         }
         base.Dispose(disposing);
      }

      public RemoveContactResult RemoveContactResult
      {
         get
         {
            RemoveContactResult result = RemoveContactResult.None;

            if (radioButtonHide.Checked)
            {
               result |= RemoveContactResult.Hide;
            }
            else if (radioButtonRemove.Checked)
            {
               result |= RemoveContactResult.Remove;
               if (checkBoxBlock.Checked) result |= RemoveContactResult.Block;
               if (checkBoxClear.Checked) result |= RemoveContactResult.Clear;
            }
            return result;
         }
      }
      public RemoveContactResult Show(Contact contact)
      {
         FContact = contact;

         UpdatewWindowView();

         return ShowDialog() == DialogResult.OK ? RemoveContactResult : RemoveContactResult.None;
      }
      public override void Translate(CultureInfo culture)
      {
         base.Translate(culture);
         UpdatewWindowView();
      }

      protected override void UpdatewWindowView()
      {
         Text = Text.Replace("<contact>", "\"" + FContact.ToString() + "\"");
         radioButtonHide.Enabled = FContact.Visible;
      }

      private void buttonOk_Click(object sender, EventArgs e)
      {
         DialogResult = DialogResult.OK;
      }
      private void buttonCancel_Click(object sender, EventArgs e)
      {
         //
      }
      private void panelBase_Paint(object sender, PaintEventArgs e)
      {
         FCommunicator.DrawTheme(FCommunicator.ColorTheme, e.Graphics, (sender as Control).ClientRectangle, ColorThemeObject.Window);
      }
      private void panelBottom_Paint(object sender, PaintEventArgs e)
      {
         FCommunicator.DrawTheme(FCommunicator.ColorTheme, e.Graphics, (sender as Control).ClientRectangle, ColorThemeObject.PanelV);
      }
      private void radioButtonRemove_CheckedChanged(object sender, EventArgs e)
      {
         buttonOk.Enabled = true;
         checkBoxBlock.Enabled = radioButtonRemove.Checked;
         checkBoxClear.Enabled = radioButtonRemove.Checked;
      }
      private void communicator_PropertyChanged(object sender, PropertyChangedEventArgs e)
      {
         if (e.PropertyName == "ColorTheme") ColorTheme = FCommunicator.ColorTheme;
         else if (e.PropertyName == "Culture") Translate(FCommunicator.Culture);
      }
   }
   [Flags]
   public enum RemoveContactResult
   {
      None,
      Hide,
      Clear,
      Block,
      Remove,
   }
}
